/*
----------------------------------------------------------------------------------------------------
This source file is part of the Gamut Framework
Copyright (c) 2007 by Ryan Holcombe

This program is free software; you can redistribute it and/or modify it under the terms of the GNU
Lesser General Public License as published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
----------------------------------------------------------------------------------------------------
*/

#include "GamutTimer.h"

namespace Gamut
{
	// -------------------------------------------------------------------------------------------//
	Timer::Timer()
	{
		reset();
	}
	
	// -------------------------------------------------------------------------------------------//
	void Timer::reset()
	{
#ifdef __linux__
		gettimeofday(&mBegin, 0);
#endif

#ifdef WIN32
		QueryPerformanceCounter( &mBegin );
#endif		
	}
	
	// -------------------------------------------------------------------------------------------//
	double Timer::getMicroSeconds()
	{
		TIME end;
		
#ifdef __linux__
		gettimeofday(&end, 0);
		return ((double)(end.tv_sec*1000000+end.tv_usec) - (mBegin.tv_sec*1000000+mBegin.tv_usec));
#endif

#ifdef WIN32
		LARGE_INTEGER frequency;
		QueryPerformanceFrequency(&frequency);
		QueryPerformanceCounter(&end);
		return ((double)(end.QuadPart - mBegin.QuadPart) / frequency.QuadPart * 1000000);		
#endif

	}


}
